var e = require;
var t = module;
var o = exports;
var Adv_skd=require("./Adv_skd");
Object.defineProperty(o, "__esModule", {value: !0});
var n = e("BaseModuleUI"),
    a = e("GlobalParams"),
    i = e("AssetsManager"),
    r = e("CommonHelper"),
    s = e("nameCfg"),
    l = e("UIManager"),
    c = e("Toast"),
    d = cc._decorator,
    h = d.ccclass,
    _ = d.property,
    u = (function (e) {
        function t() {
            var t = (null !== e && e.apply(this, arguments)) || this;
            return (
                (t.count_down_time = null),
                (t.match_tip_label = null),
                (t.player_node_view = null),
                (t.count_down = 0),
                (t.random_name = []),
                (t.random_hero = []),
                t
            );
        }
        return (
            __extends(t, e),

            (t.prototype.onDisable = function () {

                Adv_skd.default.instance.hideBannerAd();
                Adv_skd.default.instance.hideGridAdLeft();
                Adv_skd.default.instance.hideGridAdRight();
                Adv_skd.default.instance.hideGridAdTop();
                Adv_skd.default.instance.hideGridAdLeftOne();
                Adv_skd.default.instance.hideGridAdRightOne();
                Adv_skd.default.instance.hideGridAdButtom();

            }),

            (t.prototype.initView = function () {

                Adv_skd.default.instance.hideBannerAd();
                Adv_skd.default.instance.hideGridAdLeft();
                Adv_skd.default.instance.hideGridAdRight();
                Adv_skd.default.instance.hideGridAdTop();
                Adv_skd.default.instance.hideGridAdLeftOne();
                Adv_skd.default.instance.hideGridAdRightOne();
                Adv_skd.default.instance.hideGridAdButtom();
                Adv_skd.default.instance.showGridAdTop();
                Adv_skd.default.instance.showBannerAd();

                (this.count_down = 1), (this.random_name = []), this.getMatchPlayer(), this.showMatchAnime();
            }),
            (t.prototype.OnClick = function (t) {
                switch ((e.prototype.OnClick.call(this, t), t.node.name)) {
                    case "back_btn":
                        if (a.GlobalParams.PlayGuideMode) return void c.default.showNewToast("引导中请勿操作");
                        (a.GlobalParams.MathcTimeInfo.open = !0), this.node.destroy();
                }
            }),
            (t.prototype.getMatchPlayer = function () {
                a.GlobalParams.MatchGamePlayer = [];
                var e = 0,
                    t = "" != a.GlobalParams.MathcTimeInfo.name,
                    o = 0;
                t ? (o = (e = r.default.getRandomInt(2, 5)) - 2) : (e = r.default.getRandomInt(0, 3)),
                    a.GlobalParams.PlayGuideMode && (e = 4),
                    (a.GlobalParams.MatchMyIndex = e);
                var n = a.GlobalParams.PlayerInfo.value;
                this.random_name.push(n.name);
                for (var i = 0; i < e; i++)
                    this.addAIPlayer(),
                        t &&
                            i == o &&
                            ((a.GlobalParams.MatchGamePlayer[i].name = a.GlobalParams.MathcTimeInfo.name),
                            (a.GlobalParams.MatchGamePlayer[i].head = a.GlobalParams.MathcTimeInfo.head)),
                        (this.count_down += r.default.getRandomInt(0, 2));
                a.GlobalParams.MatchGamePlayer[e] = {
                    name: n.name,
                    head: n.head,
                    role_id: 0,
                    player_skill: [1, 2],
                    dower_info: [0, 0],
                    level: 1,
                    exp_num: 0,
                    kill_info: [0, 0, 0],
                    skill_info: [0, 0],
                    equip_info: [0, 0, 0, 0, 0],
                    coin: 0
                };
            }),
            (t.prototype.addAIPlayer = function () {
                var e = "";
                do {
                    e = s.default.nameList[r.default.getRandomInt(0, s.default.nameList.length - 1)];
                } while (-1 != this.random_name.indexOf(e));
                this.random_name.push(e);
                var t = 0;
                do {
                    t =
                        a.GlobalParams.GameHeroIndex[
                            r.default.getRandomInt(0, a.GlobalParams.GameHeroIndex.length - 1)
                        ];
                } while (-1 != this.random_hero.indexOf(t));
                this.random_hero.push(t);
                var o = r.default.getRandomInt(0, 4),
                    n = {
                        name: e,
                        head: r.default.getRandomInt(1, 19),
                        role_id: t,
                        player_skill: [1, 2],
                        dower_info: [o, a.GlobalParams.PlayerDowerInfo.value.dower[o]],
                        level: 1,
                        exp_num: 0,
                        kill_info: [0, 0, 0],
                        skill_info: [1, 0],
                        equip_info: [0, 0, 0, 0, 0],
                        coin: 0
                    };
                a.GlobalParams.MatchGamePlayer.push(n);
            }),
            (t.prototype.showMatchInfo = function () {
                for (var e = this, t = 0; t < this.player_node_view.childrenCount; t++) {
                    var o = this.player_node_view.children[t],
                        n = a.GlobalParams.MatchGamePlayer[t];
                    (o.getChildByName("player_name").getComponent(cc.Label).string = n ? n.name : ""),
                        (o.getChildByName("head_image").getComponent(cc.Sprite).spriteFrame = n
                            ? i.default.getInstance().getPlayerHeadFrame(n.head)
                            : null),
                        (o.getChildByName("my").active = t == a.GlobalParams.MatchMyIndex),
                        (o.getChildByName("player_name").color =
                            t == a.GlobalParams.MatchMyIndex ? cc.color(20, 255, 50) : cc.color(255, 255, 255));
                }
                a.GlobalParams.MatchGamePlayer.length < 6
                    ? this.scheduleOnce(function () {
                          e.addAIPlayer(), e.showMatchInfo();
                      }, r.default.getRandomInt(0, 3))
                    : this.scheduleOnce(function () {
                          e.unscheduleAllCallbacks(),
                              cc.find("UIManager").getComponent(l.default).showPopup("ChooseHoreViewUI"),
                              e.node.destroy();
                      }, 1);
            }),
            (t.prototype.showMatchAnime = function () {
                var e = this;
                (this.player_node_view.active = !1),
                    (this.match_tip_label.node.active = !1),
                    (this.count_down_time.node.scale = 0.1),
                    this.scheduleOnce(function () {
                        (e.player_node_view.active = !0),
                            (e.match_tip_label.node.active = !0),
                            e.showMatchInfo(),
                            e.countDown();
                    }, 0.3);
            }),
            (t.prototype.countDown = function () {
                var e = this;
                (this.count_down_time.string = "" + this.count_down), (this.match_tip_label.string = "正在匹配");
                for (var t = 0; t < 3; t++) t < this.count_down % 4 && (this.match_tip_label.string += "。");
                cc.tween(this.count_down_time.node)
                    .to(0.8, {scale: 1})
                    .delay(0.2)
                    .call(function () {
                        (e.count_down_time.node.scale = 0.1), e.count_down++, e.countDown();
                    })
                    .start();
            }),
            __decorate([_(cc.Label)], t.prototype, "count_down_time", void 0),
            __decorate([_(cc.Label)], t.prototype, "match_tip_label", void 0),
            __decorate([_(cc.Node)], t.prototype, "player_node_view", void 0),
            __decorate([h], t)
        );
    })(n.default);
o.default = u;
